<?php

/**
 * productionlist actions.
 *
 * @package    ppstool
 * @subpackage productionlist
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class productionActions extends sfActions
{
	public function preExecute()
	{
		$this->xml = simplexml_load_string($this->getUser()->getAttribute('xmlin'));
	}
	public function executeIndex(sfWebRequest $request)
	{

	}

	public function executeSafetystock($request)
	{
		$this->getUser()->setAttribute('progress', 40);
		if (!$this->getUser()->getAttribute('xmlin')) {
			$this->getUser()->setFlash('error', "Bitte zuerst den Import ausführen!", true);
			$this->redirect("import/index");
		}

	}
	public function executeSavesafetystock($request)
	{
		$safetystock_id = $request->getParameter('safetystock');
		$this->getUser()->setAttribute('safetystock',$safetystock_id);
		//echo $request->getParameter('safetystock');
		switch ($safetystock_id){
			case "0":
				$artikelstock = array(
	        "1" => "0",
			"51" => "0",
	        "50" => "0",
			"4" => "0",
			"10" => "0",
			"49" => "0",
			"7" => "0",
			"13" => "0",
			"18" => "0",
	        "2" => "0",
	        "56" => "0",
	        "55" => "0",
	        "5" => "0",
	        "11" => "0",
	        "54" => "0",
	        "8" => "0",
	        "14" => "0",
	        "19" => "0",
	        "3" => "0",
	        "31" => "0",
	        "30" => "0",
	        "6" => "0",
	        "12" => "0",
	        "29" => "0",
	        "9" => "0",
	        "15" => "0",
	        "20"=> "0",
	        "26" => "0",
	        "16" => "0",
	        "17" => "0"
	        );
	        break;
			case "1":
				$artikelstock = array(
	        "1" => "50",
			"51" => "50",
	        "50" => "50",
			"4" => "50",
			"10" => "50",
			"49" => "50",
			"7" => "50",
			"13" => "50",
			"18" => "50",
	        "2" => "50",
	        "56" => "50",
	        "55" => "50",
	        "5" => "50",
	        "11" => "50",
	        "54" => "50",
	        "8" => "50",
	        "14" => "50",
	        "19" => "50",
	        "3" => "50",
	        "31" => "50",
	        "30" => "50",
	        "6" => "50",
	        "12" => "50",
	        "29" => "50",
	        "9" => "50",
	        "15" => "50",
	        "20" => "50",
	        "26" => "150",
	        "16" => "150",
	        "17" => "150"
	        );
	        break;
			case "2":
				$artikelstock = array(
	        "1" => "50",
			"51" => "50",
	        "50" => "50",
			"4" => "100",
			"10" => "100",
			"49" => "50",
			"7" => "100",
			"13" => "100",
			"18" => "100",
	        "2" => "50",
	        "56" => "50",
	        "55" => "50",
	        "5" => "100",
	        "11" => "100",
	        "54" => "50",
	        "8" => "100",
	        "14" => "100",
	        "19" => "100",
	        "3" => "50",
	        "31" => "50",
	        "30" => "50",
	        "6" => "100",
	        "12" => "100",
	        "29" => "50",
	        "9" => "100",
	        "15" => "100",
	        "20"=> "100",
	        "26" => "300",
	        "16" => "300",
	        "17" => "300"
	        );
	        break;
			case "3":
				$artikelstock = array(
	        "1" => "100",
			"51" => "100",
			"4" => "100",
			"10" => "100",
			"49" => "100",
			"7" => "100",
			"13" => "100",
			"18" => "100",
	        "2" => "100",
	        "56" => "100",
	        "55" => "100",
	        "5" => "100",
	        "11" => "100",
	        "54" => "100",
	        "8" => "100",
	        "14" => "100",
	        "19" => "100",
	        "3" => "100",
	        "31" => "100",
	        "30" => "100",
	        "6" => "100",
	        "12" => "100",
	        "29" => "100",
	        "9" => "100",
	        "15" => "100",
	        "20" => "100",
	        "26" => "300",
	        "16" => "300",
	        "17" => "300",	        
				);
				break;
		}
		$this->getUser()->setAttribute('as', $artikelstock);

		//$this->redirect('overview/getfromxml');
		$this->redirect('overview/calculate');
	}

	public function executeGetfromxml($request)
	{
		//Lagerbestand
		$stockamount = array();
		foreach ($this->xml->warehousestock->article as $artikel)
		{
			$stockamount[(int)$artikel->attributes()->id] = (int)$artikel->attributes()->amount;
		}
		$this->getUser()->setAttribute('sa', $stockamount);
			
			
		//Warteteile
		$waitingstock= array();
		foreach ($this->xml->waitinglistworkstations->workplace as $workplace)
		{
			if((int)$workplace->attributes()->timeneed<>0)
			{
				foreach($workplace->waitinglist as $waitinglist)
				{
					if(array_key_exists(((int)$waitinglist->attributes()->item),$waitingstock))
					{
						$waitingstock[(int)$waitinglist->attributes()->item]+=(int)$waitinglist->attributes()->amount;
					}
					else
					{
						$waitingstock[(int)$waitinglist->attributes()->item] = (int)$waitinglist->attributes()->amount;
					}
				}
			}
		}
		$this->getUser()->setAttribute('ws', $waitingstock);

		//Aufträge in Bearbeitung
		$orderstock = array();
		foreach ($this->xml->ordersinwork->workplace as $workplace)
		{
			if(array_key_exists(((int)$workplace->attributes()->item),$orderstock))
			{
				$orderstock[(int)$workplace->attributes()->item]+=(int)$workplace->attributes()->amount;
			}
			else
			{
				$orderstock[(int)$workplace->attributes()->item] = (int)$workplace->attributes()->amount;
			}
		}
		$this->getUser()->setAttribute('os', $orderstock);


		//Missingparts
		$missingstock = array();
		foreach ($this->xml->waitingliststock->missingpart as $missingpart)
		{
			$missingstock[(int)$missingpart->waitinglist->attributes()->item] = (int)$missingpart->waitinglist->attributes()->amount;
		}
		$this->getUser()->setAttribute('ms', $missingstock);
		//print_r($missingstock);
			
		//Zeitr�ckstand Arbeitsplatz + in Bearbeitung
		$workingstock = array();
		foreach ($this->xml->waitinglistworkstations->workplace as $workplace)
		{
			$workingstock[(int)$workplace->attributes()->id]=(int)$workplace->attributes()->timeneed;
		}
		foreach ($this->xml->ordersinwork->workplace as $workplace)
		{
			$workingstock[(int)$workplace->attributes()->id] += (int)$workplace->attributes()->timeneed;
		}
			
		$this->getUser()->setAttribute('workingstock', $workingstock);
			
		//Offene Bestellungen
		$futurestock = array();
		foreach ($this->xml->futureinwardstockmovement->order as $order)
		{
			if(array_key_exists(((int)$order->attributes()->article),$futurestock))
			{
				$futurestock[(int)$order->attributes()->article]+=(int)$order->attributes()->amount;
			}
			else
			{
				$futurestock[(int)$order->attributes()->article] = (int)$order->attributes()->amount;
			}
		}
		$this->getUser()->setAttribute('fis', $futurestock);

		//$this->redirect('production/product1');
	}

	public function executeProduct1($request)
	{
		$artikelstock = $this->getUser()->getAttribute('as');
		$orderstock = $this->getUser()->getAttribute('os');
		$waitingstock = $this->getUser()->getAttribute('ws');
		$stockamount = $this->getUser()->getAttribute('sa');
		$missingstock = $this->getUser()->getAttribute('ms');
			
		//print_r($waitingstock);
			
		echo "<br>";

		//Berechnung P1
		$p1n = (int)$this->getUser()->getAttribute('p1n');
		if(isset($waitingstock["1"])==false)
		{
			$waitingstock["1"]=0;
		}
		if(isset($stockamount["1"])==false)
		{
			$stockamount["1"]=0;
		}
		if(isset($orderstock["1"])==false)
		{
			$orderstock["1"]=0;
		}
		if(isset($missingstock["1"])==false)
		{
			$missingstock["1"]=0;
		}
		$artikelstock["1"] += $p1n - $stockamount["1"]-$waitingstock["1"]-$orderstock["1"]-$missingstock["1"];
		if($artikelstock["1"]<0)
		{
			$artikelstock["1"]=0;
		}
		echo $artikelstock["1"]."<br>";
			
		//Mehrfachverwendteile E26
		if(isset($waitingstock["26"])==false)
		{
			$waitingstock["26"]=0;
		}
		if(isset($stockamount["26"])==false)
		{
			$stockamount["26"]=0;
		}
		if(isset($orderstock["26"])==false)
		{
			$orderstock["26"]=0;
		}
		if(isset($missingstock["26"])==false)
		{
			$missingstock["26"]=0;
		}
		$artikelstock["26"]+= $artikelstock["1"] + $waitingstock["1"] + $missingstock["1"] - ($waitingstock["26"]/3)-($stockamount["26"]/3)-($orderstock["26"]/3)-($missingstock["26"]/3);
		if($artikelstock["26"]<0)
		{
			$artikelstock["26"]=0;
		}
		echo $artikelstock["26"]."<br>";
			
		//E51
		if(isset($waitingstock["51"])==false)
		{
			$waitingstock["51"]=0;
		}
		if(isset($stockamount["51"])==false)
		{
			$stockamount["51"]=0;
		}
		if(isset($orderstock["51"])==false)
		{
			$orderstock["51"]=0;
		}
		if(isset($missingstock["51"])==false)
		{
			$missingstock["51"]=0;
		}
		$artikelstock["51"]+= $artikelstock["1"] + $waitingstock["1"] + $missingstock["1"] - $waitingstock["51"]-$stockamount["51"]-$orderstock["51"]-$missingstock["51"];
		if($artikelstock["51"]<0)
		{
			$artikelstock["51"]=0;
		}
		echo $artikelstock["51"]."<br>";
			
		// Mehrfachverwendteile E16
		if(isset($waitingstock["16"])==false)
		{
			$waitingstock["16"]=0;
		}
		if(isset($stockamount["16"])==false)
		{
			$stockamount["16"]=0;
		}
		if(isset($orderstock["16"])==false)
		{
			$orderstock["16"]=0;
		}
		if(isset($missingstock["16"])==false)
		{
			$missingstock["16"]=0;
		}
		$artikelstock["16"]+= $artikelstock["51"] + $waitingstock["51"] + $missingstock["51"]- ((int)$waitingstock["16"]/3)-((int)$stockamount["16"]/3)-((int)$orderstock["16"]/3)-($missingstock["16"]/3);
		if($artikelstock["16"]<0)
		{
			$artikelstock["16"]=0;
		}
		echo $artikelstock["16"]."<br>";
			
		//Mehrfachverwendteile E17
		if(isset($waitingstock["17"])==false)
		{
			$waitingstock["17"]=0;
		}
		if(isset($stockamount["17"])==false)
		{
			$stockamount["17"]=0;
		}
		if(isset($orderstock["17"])==false)
		{
			$orderstock["17"]=0;
		}
		if(isset($missingstock["17"])==false)
		{
			$missingstock["17"]=0;
		}
		$artikelstock["17"]+= $artikelstock["51"] + $waitingstock["51"] + $missingstock["51"] - ($waitingstock["17"]/3)-($stockamount["17"]/3)-($orderstock["17"]/3)-($missingstock["17"]/3);
		if($artikelstock["17"]<0)
		{
			$artikelstock["17"]=0;
		}
		echo $artikelstock["17"]."<br>";

		//E50
		if(isset($waitingstock["50"])==false)
		{
			$waitingstock["50"]=0;
		}
		if(isset($stockamount["50"])==false)
		{
			$stockamount["50"]=0;
		}
		if(isset($orderstock["50"])==false)
		{
			$orderstock["50"]=0;
		}
		if(isset($missingstock["50"])==false)
		{
			$missingstock["50"]=0;
		}
		$artikelstock["50"]+= $artikelstock["51"] + $waitingstock["51"] + $missingstock["51"] - $waitingstock["50"]-$stockamount["50"]-$orderstock["50"]-$missingstock["50"];
		if($artikelstock["50"]<0)
		{
			$artikelstock["50"]=0;
		}
		echo $artikelstock["50"]."<br>";
			
		//E4
		if(isset($waitingstock["4"])==false)
		{
			$waitingstock["4"]=0;
		}
		if(isset($stockamount["4"])==false)
		{
			$stockamount["4"]=0;
		}
		if(isset($orderstock["4"])==false)
		{
			$orderstock["4"]=0;
		}
		if(isset($missingstock["4"])==false)
		{
			$missingstock["4"]=0;
		}
		$artikelstock["4"]+= $artikelstock["50"] + $waitingstock["50"] + $missingstock["50"] - $waitingstock["4"]-$stockamount["4"]-$orderstock["4"]-$missingstock["4"];
		if($artikelstock["4"]<0)
		{
			$artikelstock["4"]=0;
		}
		echo $artikelstock["4"]."<br>";
			
		//E10
		if(isset($waitingstock["10"])==false)
		{
			$waitingstock["10"]=0;
		}
		if(isset($stockamount["10"])==false)
		{
			$stockamount["10"]=0;
		}
		if(isset($orderstock["10"])==false)
		{
			$orderstock["10"]=0;
		}
		if(isset($missingstock["10"])==false)
		{
			$missingstock["10"]=0;
		}
		$artikelstock["10"]+= $artikelstock["50"] + $waitingstock["50"] + $missingstock["50"] - $waitingstock["10"]-$stockamount["10"]-$orderstock["10"]-$missingstock["10"];
		if($artikelstock["10"]<0)
		{
			$artikelstock["10"]=0;
		}
		echo $artikelstock["10"]."<br>";
			
		//E49
		if(isset($waitingstock["49"])==false)
		{
			$waitingstock["49"]=0;
		}
		if(isset($stockamount["49"])==false)
		{
			$stockamount["49"]=0;
		}
		if(isset($orderstock["49"])==false)
		{
			$orderstock["49"]=0;
		}
		if(isset($missingstock["49"])==false)
		{
			$missingstock["49"]=0;
		}
		$artikelstock["49"]+= $artikelstock["50"] + $waitingstock["50"] + $missingstock["50"] - $waitingstock["49"]-$stockamount["49"]-$orderstock["49"]-$missingstock["49"];
		if($artikelstock["49"]<0)
		{
			$artikelstock["49"]=0;
		}
		echo $artikelstock["49"]."<br>";
			
		//E7
		if(isset($waitingstock["7"])==false)
		{
			$waitingstock["7"]=0;
		}
		if(isset($stockamount["7"])==false)
		{
			$stockamount["7"]=0;
		}
		if(isset($orderstock["7"])==false)
		{
			$orderstock["7"]=0;
		}
		if(isset($missingstock["7"])==false)
		{
			$missingstock["7"]=0;
		}
		$artikelstock["7"]+= $artikelstock["49"] + $waitingstock["49"] + $missingstock["49"] - $waitingstock["7"]-$stockamount["7"]-$orderstock["7"]-$missingstock["7"];
		if($artikelstock["7"]<0)
		{
			$artikelstock["7"]=0;
		}
		echo $artikelstock["7"]."<br>";
			
		//E13
		if(isset($waitingstock["13"])==false)
		{
			$waitingstock["13"]=0;
		}
		if(isset($stockamount["13"])==false)
		{
			$stockamount["13"]=0;
		}
		if(isset($orderstock["13"])==false)
		{
			$orderstock["13"]=0;
		}
		if(isset($missingstock["13"])==false)
		{
			$missingstock["13"]=0;
		}
		$artikelstock["13"]+= $artikelstock["49"] + $waitingstock["49"] + $missingstock["49"] - $waitingstock["13"]-$stockamount["13"]-$orderstock["13"]-$missingstock["13"];
		if($artikelstock["13"]<0)
		{
			$artikelstock["13"]=0;
		}
		echo $artikelstock["13"]."<br>";
			
		//E18
		if(isset($waitingstock["18"])==false)
		{
			$waitingstock["18"]=0;
		}
		if(isset($stockamount["18"])==false)
		{
			$stockamount["18"]=0;
		}
		if(isset($orderstock["18"])==false)
		{
			$orderstock["18"]=0;
		}
		if(isset($missingstock["18"])==false)
		{
			$missingstock["18"]=0;
		}
		$artikelstock["18"]+= $artikelstock["49"] + $waitingstock["49"] + $missingstock["49"] - $waitingstock["18"]-$stockamount["18"]-$orderstock["18"]-$missingstock["18"];
		if($artikelstock["18"]<0)
		{
			$artikelstock["18"]=0;
		}
		echo $artikelstock["18"]."<br>";
		$this->getUser()->getAttributeHolder()->remove('as');
		$this->getUser()->setAttribute('as', $artikelstock);

		//$this->redirect('production/product2');
	}

	public function executeProduct2($request)
	{
		$artikelstock = $this->getUser()->getAttribute('as');
		$orderstock = $this->getUser()->getAttribute('os');
		$waitingstock = $this->getUser()->getAttribute('ws');
		$stockamount = $this->getUser()->getAttribute('sa');
		$missingstock = $this->getUser()->getAttribute('ms');

		//Berechnung P2
		$p1n = (int)$this->getUser()->getAttribute('p2n');
		if(isset($waitingstock["2"])==false)
		{
			$waitingstock["2"]=0;
		}
		if(isset($stockamount["2"])==false)
		{
			$stockamount["2"]=0;
		}
		if(isset($orderstock["2"])==false)
		{
			$orderstock["2"]=0;
		}
		if(isset($missingstock["2"])==false)
		{
			$missingstock["2"]=0;
		}
		$artikelstock["2"] += $p1n - $stockamount["2"]-$waitingstock["2"]-$orderstock["2"]-$missingstock["2"];
		if($artikelstock["2"]<0)
		{
			$artikelstock["2"]=0;
		}
		echo $artikelstock["2"]."<br>";
			
		//Mehrfachverwendteile E26
		if(isset($waitingstock["26"])==false)
		{
			$waitingstock["26"]=0;
		}
		if(isset($stockamount["26"])==false)
		{
			$stockamount["26"]=0;
		}
		if(isset($orderstock["26"])==false)
		{
			$orderstock["26"]=0;
		}
		if(isset($missingstock["26"])==false)
		{
			$missingstock["26"]=0;
		}
		$artikelstock["26"]+= $artikelstock["2"] + $waitingstock["2"] + $missingstock["2"] - ($waitingstock["26"]/3)-($stockamount["26"]/3)-($orderstock["26"]/3)-($missingstock["26"]/3);
		if($artikelstock["26"]<0)
		{
			$artikelstock["26"]=0;
		}
		echo $artikelstock["26"]."<br>";
			
		//E56
		if(isset($waitingstock["56"])==false)
		{
			$waitingstock["56"]=0;
		}
		if(isset($stockamount["56"])==false)
		{
			$stockamount["56"]=0;
		}
		if(isset($orderstock["56"])==false)
		{
			$orderstock["56"]=0;
		}
		if(isset($missingstock["56"])==false)
		{
			$missingstock["56"]=0;
		}
		$artikelstock["56"]+= $artikelstock["2"] + $waitingstock["2"] + $missingstock["2"] - $waitingstock["56"]-$stockamount["56"]-$orderstock["56"]-$missingstock["56"];
		if($artikelstock["56"]<0)
		{
			$artikelstock["56"]=0;
		}
		echo $artikelstock["56"]."<br>";
			
		// Mehrfachverwendteile E16
		if(isset($waitingstock["16"])==false)
		{
			$waitingstock["16"]=0;
		}
		if(isset($stockamount["16"])==false)
		{
			$stockamount["16"]=0;
		}
		if(isset($orderstock["16"])==false)
		{
			$orderstock["16"]=0;
		}
		if(isset($missingstock["16"])==false)
		{
			$missingstock["16"]=0;
		}
			
		$artikelstock["16"]+= $artikelstock["56"] + $waitingstock["56"] + $missingstock["56"]- ((int)$waitingstock["16"]/3)-((int)$stockamount["16"]/3)-((int)$orderstock["16"]/3)-($missingstock["16"]/3);
		if($artikelstock["16"]<0)
		{
			$artikelstock["16"]=0;
		}
		echo $artikelstock["16"]."<br>";
			
		//Mehrfachverwendteile E17
		if(isset($waitingstock["17"])==false)
		{
			$waitingstock["17"]=0;
		}
		if(isset($stockamount["17"])==false)
		{
			$stockamount["17"]=0;
		}
		if(isset($orderstock["17"])==false)
		{
			$orderstock["17"]=0;
		}
		if(isset($missingstock["17"])==false)
		{
			$missingstock["17"]=0;
		}
		$artikelstock["17"]+= $artikelstock["56"] + $waitingstock["56"] + $missingstock["56"] - ($waitingstock["17"]/3)-($stockamount["17"]/3)-($orderstock["17"]/3)-($missingstock["17"]/3);
		if($artikelstock["17"]<0)
		{
			$artikelstock["17"]=0;
		}
		echo $artikelstock["17"]."<br>";

		//E55
		if(isset($waitingstock["55"])==false)
		{
			$waitingstock["55"]=0;
		}
		if(isset($stockamount["55"])==false)
		{
			$stockamount["55"]=0;
		}
		if(isset($orderstock["55"])==false)
		{
			$orderstock["55"]=0;
		}
		if(isset($missingstock["55"])==false)
		{
			$missingstock["55"]=0;
		}
		$artikelstock["55"]+= $artikelstock["56"] + $waitingstock["56"] + $missingstock["56"] - $waitingstock["55"]-$stockamount["55"]-$orderstock["55"]-$missingstock["55"];
		if($artikelstock["55"]<0)
		{
			$artikelstock["55"]=0;
		}
		echo $artikelstock["55"]."<br>";
			
		//E5
		if(isset($waitingstock["5"])==false)
		{
			$waitingstock["5"]=0;
		}
		if(isset($stockamount["5"])==false)
		{
			$stockamount["5"]=0;
		}
		if(isset($orderstock["5"])==false)
		{
			$orderstock["5"]=0;
		}
		if(isset($missingstock["5"])==false)
		{
			$missingstock["5"]=0;
		}
		$artikelstock["5"]+= $artikelstock["55"] + $waitingstock["55"] + $missingstock["55"] - $waitingstock["5"]-$stockamount["5"]-$orderstock["5"]-$missingstock["5"];
		if($artikelstock["5"]<0)
		{
			$artikelstock["5"]=0;
		}
		echo $artikelstock["5"]."<br>";
			
		//E11
		if(isset($waitingstock["11"])==false)
		{
			$waitingstock["11"]=0;
		}
		if(isset($stockamount["11"])==false)
		{
			$stockamount["11"]=0;
		}
		if(isset($orderstock["11"])==false)
		{
			$orderstock["11"]=0;
		}
		if(isset($missingstock["11"])==false)
		{
			$missingstock["11"]=0;
		}
		$artikelstock["11"]+= $artikelstock["55"] + $waitingstock["55"] + $missingstock["55"] - $waitingstock["11"]-$stockamount["11"]-$orderstock["11"]-$missingstock["11"];
		if($artikelstock["11"]<0)
		{
			$artikelstock["11"]=0;
		}
		echo $artikelstock["11"]."<br>";
			
		//E54
		if(isset($waitingstock["54"])==false)
		{
			$waitingstock["54"]=0;
		}
		if(isset($stockamount["54"])==false)
		{
			$stockamount["54"]=0;
		}
		if(isset($orderstock["54"])==false)
		{
			$orderstock["54"]=0;
		}
		if(isset($missingstock["54"])==false)
		{
			$missingstock["54"]=0;
		}
		$artikelstock["54"]+= $artikelstock["55"] + $waitingstock["55"] + $missingstock["55"] - $waitingstock["54"]-$stockamount["54"]-$orderstock["54"]-$missingstock["54"];
		if($artikelstock["54"]<0)
		{
			$artikelstock["54"]=0;
		}
		echo $artikelstock["54"]."<br>";
			
		//E8
		if(isset($waitingstock["8"])==false)
		{
			$waitingstock["8"]=0;
		}
		if(isset($stockamount["8"])==false)
		{
			$stockamount["8"]=0;
		}
		if(isset($orderstock["8"])==false)
		{
			$orderstock["8"]=0;
		}
		if(isset($missingstock["8"])==false)
		{
			$missingstock["8"]=0;
		}
		$artikelstock["8"]+= $artikelstock["54"] + $waitingstock["54"] + $missingstock["54"] - $waitingstock["8"]-$stockamount["8"]-$orderstock["8"]-$missingstock["8"];
		if($artikelstock["8"]<0)
		{
			$artikelstock["8"]=0;
		}
		echo $artikelstock["8"]."<br>";
			
		//E14
		if(isset($waitingstock["14"])==false)
		{
			$waitingstock["14"]=0;
		}
		if(isset($stockamount["14"])==false)
		{
			$stockamount["14"]=0;
		}
		if(isset($orderstock["14"])==false)
		{
			$orderstock["14"]=0;
		}
		if(isset($missingstock["14"])==false)
		{
			$missingstock["14"]=0;
		}
		$artikelstock["14"]+= $artikelstock["54"] + $waitingstock["54"] + $missingstock["54"] - $waitingstock["14"]-$stockamount["14"]-$orderstock["14"]-$missingstock["14"];
		if($artikelstock["14"]<0)
		{
			$artikelstock["14"]=0;
		}
		echo $artikelstock["14"]."<br>";
			
		//E19
		if(isset($waitingstock["19"])==false)
		{
			$waitingstock["19"]=0;
		}
		if(isset($stockamount["19"])==false)
		{
			$stockamount["19"]=0;
		}
		if(isset($orderstock["19"])==false)
		{
			$orderstock["19"]=0;
		}
		if(isset($missingstock["19"])==false)
		{
			$missingstock["19"]=0;
		}
		$artikelstock["19"]+= $artikelstock["54"] + $waitingstock["54"] + $missingstock["54"] - $waitingstock["19"]-$stockamount["19"]-$orderstock["19"]-$missingstock["19"];
		if($artikelstock["19"]<0)
		{
			$artikelstock["19"]=0;
		}
		echo $artikelstock["19"]."<br>";
		$this->getUser()->getAttributeHolder()->remove('as');
		$this->getUser()->setAttribute('as', $artikelstock);
		//$this->redirect('production/product3');
	}

	public function executeProduct3($request)
	{
		$artikelstock = $this->getUser()->getAttribute('as');
		$orderstock = $this->getUser()->getAttribute('os');
		$waitingstock = $this->getUser()->getAttribute('ws');
		$stockamount = $this->getUser()->getAttribute('sa');
		$missingstock = $this->getUser()->getAttribute('ms');

		//Berechnung P3
		$p3n = (int)$this->getUser()->getAttribute('p3n');
		if(isset($waitingstock["3"])==false)
		{
			$waitingstock["3"]=0;
		}
		if(isset($stockamount["3"])==false)
		{
			$stockamount["3"]=0;
		}
		if(isset($orderstock["3"])==false)
		{
			$orderstock["3"]=0;
		}
		if(isset($missingstock["3"])==false)
		{
			$missingstock["3"]=0;
		}
		$artikelstock["3"] += $p3n - $stockamount["3"]-$waitingstock["3"]-$orderstock["3"]-$missingstock["3"];
		if($artikelstock["3"]<0)
		{
			$artikelstock["3"]=0;
		}
		echo $artikelstock["3"]."<br>";
			
		//Mehrfachverwendteile E26
		if(isset($waitingstock["26"])==false)
		{
			$waitingstock["26"]=0;
		}
		if(isset($stockamount["26"])==false)
		{
			$stockamount["26"]=0;
		}
		if(isset($orderstock["26"])==false)
		{
			$orderstock["26"]=0;
		}
		if(isset($missingstock["26"])==false)
		{
			$missingstock["26"]=0;
		}
		$artikelstock["26"]+= $artikelstock["3"] + $waitingstock["3"] + $missingstock["3"] - ($waitingstock["26"]/3)-($stockamount["26"]/3)-($orderstock["26"]/3)-($missingstock["26"]/3);
		if($artikelstock["26"]<0)
		{
			$artikelstock["26"]=0;
		}
		echo $artikelstock["26"]."<br>";
			
		//E31
		if(isset($waitingstock["31"])==false)
		{
			$waitingstock["31"]=0;
		}
		if(isset($stockamount["31"])==false)
		{
			$stockamount["31"]=0;
		}
		if(isset($orderstock["31"])==false)
		{
			$orderstock["31"]=0;
		}
		if(isset($missingstock["31"])==false)
		{
			$missingstock["31"]=0;
		}
		$artikelstock["31"]+= $artikelstock["3"] + $waitingstock["3"] + $missingstock["3"] - $waitingstock["31"]-$stockamount["31"]-$orderstock["31"]-$missingstock["31"];
		if($artikelstock["31"]<0)
		{
			$artikelstock["31"]=0;
		}
		echo $artikelstock["31"]."<br>";
			
		// Mehrfachverwendteile E16
		if(isset($waitingstock["16"])==false)
		{
			$waitingstock["16"]=0;
		}
		if(isset($stockamount["16"])==false)
		{
			$stockamount["16"]=0;
		}
		if(isset($orderstock["16"])==false)
		{
			$orderstock["16"]=0;
		}
		if(isset($missingstock["16"])==false)
		{
			$missingstock["16"]=0;
		}
		$artikelstock["16"]+= $artikelstock["31"] + $waitingstock["31"] + $missingstock["31"]- ((int)$waitingstock["16"]/3)-((int)$stockamount["16"]/3)-((int)$orderstock["16"]/3)-($missingstock["16"]/3);
		if($artikelstock["16"]<0)
		{
			$artikelstock["16"]=0;
		}
		echo $artikelstock["16"]."<br>";
			
		//Mehrfachverwendteile E17
		if(isset($waitingstock["17"])==false)
		{
			$waitingstock["17"]=0;
		}
		if(isset($stockamount["17"])==false)
		{
			$stockamount["17"]=0;
		}
		if(isset($orderstock["17"])==false)
		{
			$orderstock["17"]=0;
		}
		if(isset($missingstock["17"])==false)
		{
			$missingstock["17"]=0;
		}
		$artikelstock["17"]+= $artikelstock["31"] + $waitingstock["31"] + $missingstock["31"] - ($waitingstock["17"]/3)-($stockamount["17"]/3)-($orderstock["17"]/3)-($missingstock["17"]/3);
		if($artikelstock["17"]<0)
		{
			$artikelstock["17"]=0;
		}
		echo $artikelstock["17"]."<br>";

		//E30
		if(isset($waitingstock["30"])==false)
		{
			$waitingstock["30"]=0;
		}
		if(isset($stockamount["30"])==false)
		{
			$stockamount["30"]=0;
		}
		if(isset($orderstock["30"])==false)
		{
			$orderstock["30"]=0;
		}
		if(isset($missingstock["30"])==false)
		{
			$missingstock["30"]=0;
		}
		$artikelstock["30"]+= $artikelstock["31"] + $waitingstock["31"] + $missingstock["31"] - $waitingstock["30"]-$stockamount["30"]-$orderstock["30"]-$missingstock["30"];
		if($artikelstock["30"]<0)
		{
			$artikelstock["30"]=0;
		}
		echo $artikelstock["30"]."<br>";
			
		//E6
		if(isset($waitingstock["6"])==false)
		{
			$waitingstock["6"]=0;
		}
		if(isset($stockamount["6"])==false)
		{
			$stockamount["6"]=0;
		}
		if(isset($orderstock["6"])==false)
		{
			$orderstock["6"]=0;
		}
		if(isset($missingstock["6"])==false)
		{
			$missingstock["6"]=0;
		}
		$artikelstock["6"]+= $artikelstock["30"] + $waitingstock["30"] + $missingstock["30"] - $waitingstock["6"]-$stockamount["6"]-$orderstock["6"]-$missingstock["6"];
		if($artikelstock["6"]<0)
		{
			$artikelstock["6"]=0;
		}
		echo $artikelstock["6"]."<br>";
			
		//E12
		if(isset($waitingstock["12"])==false)
		{
			$waitingstock["12"]=0;
		}
		if(isset($stockamount["12"])==false)
		{
			$stockamount["12"]=0;
		}
		if(isset($orderstock["12"])==false)
		{
			$orderstock["12"]=0;
		}
		if(isset($missingstock["12"])==false)
		{
			$missingstock["12"]=0;
		}
		$artikelstock["12"]+= $artikelstock["30"] + $waitingstock["30"] + $missingstock["30"] - $waitingstock["12"]-$stockamount["12"]-$orderstock["12"]-$missingstock["12"];
		if($artikelstock["12"]<0)
		{
			$artikelstock["12"]=0;
		}
		echo $artikelstock["12"]."<br>";
			
		//E29
		if(isset($waitingstock["29"])==false)
		{
			$waitingstock["29"]=0;
		}
		if(isset($stockamount["29"])==false)
		{
			$stockamount["29"]=0;
		}
		if(isset($orderstock["29"])==false)
		{
			$orderstock["29"]=0;
		}
		if(isset($missingstock["29"])==false)
		{
			$missingstock["29"]=0;
		}
		$artikelstock["29"]+= $artikelstock["30"] + $waitingstock["30"] + $missingstock["30"] - $waitingstock["29"]-$stockamount["29"]-$orderstock["29"]-$missingstock["29"];
		if($artikelstock["29"]<0)
		{
			$artikelstock["29"]=0;
		}
		echo $artikelstock["29"]."<br>";
			
		//E9
		if(isset($waitingstock["9"])==false)
		{
			$waitingstock["9"]=0;
		}
		if(isset($stockamount["9"])==false)
		{
			$stockamount["9"]=0;
		}
		if(isset($orderstock["9"])==false)
		{
			$orderstock["9"]=0;
		}
		if(isset($missingstock["9"])==false)
		{
			$missingstock["9"]=0;
		}
		$artikelstock["9"]+= $artikelstock["29"] + $waitingstock["29"] + $missingstock["29"] - $waitingstock["9"]-$stockamount["9"]-$orderstock["9"]-$missingstock["9"];
		if($artikelstock["9"]<0)
		{
			$artikelstock["9"]=0;
		}
		echo $artikelstock["9"]."<br>";
			
		//E15
		if(isset($waitingstock["15"])==false)
		{
			$waitingstock["15"]=0;
		}
		if(isset($stockamount["15"])==false)
		{
			$stockamount["15"]=0;
		}
		if(isset($orderstock["15"])==false)
		{
			$orderstock["15"]=0;
		}
		if(isset($missingstock["15"])==false)
		{
			$missingstock["15"]=0;
		}
		$artikelstock["15"]+= $artikelstock["29"] + $waitingstock["29"] + $missingstock["29"] - $waitingstock["15"]-$stockamount["15"]-$orderstock["15"]-$missingstock["15"];
		if($artikelstock["15"]<0)
		{
			$artikelstock["15"]=0;
		}
		echo $artikelstock["15"]."<br>";
			
		//E20
		if(isset($waitingstock["20"])==false)
		{
			$waitingstock["20"]=0;
		}
		if(isset($stockamount["20"])==false)
		{
			$stockamount["20"]=0;
		}
		if(isset($orderstock["20"])==false)
		{
			$orderstock["20"]=0;
		}
		if(isset($missingstock["20"])==false)
		{
			$missingstock["20"]=0;
		}
		$artikelstock["20"]+= $artikelstock["29"] + $waitingstock["29"] + $missingstock["29"] - $waitingstock["20"]-$stockamount["20"]-$orderstock["20"]-$missingstock["20"];
		if($artikelstock["20"]<0)
		{
			$artikelstock["20"]=0;
		}
		echo $artikelstock["20"]."<br>";
		$this->getUser()->getAttributeHolder()->remove('as');
		$this->getUser()->setAttribute('as', $artikelstock);
		//array runden für e-mail
		foreach ($artikelstock as $artikel)
		{
			$artikel= round($artikel,0);
		}
		//$this->redirect('workingtime/calculation');
	}
}
